

export class Enemy {
    fun:string="l"
    enactionindex:number=1;
    enactioncount:number=4;
    enactionstart:number=0;
    enactionend:number=0;
    imgpath:string="../images/l";
    enlive:number=20;
    enlivelimit:number=50;
    enwidth:number=30;
    enheight:number=40;
    en_x:number=0;
    en_y:number=0;
    speed:number=3;
    enadio=new Audio();
    currentdeadstr:string="";

    enemydraw=(ptctx:any,max_width:number,max_height:number)=>{
        let eImg = new Image();
        //let enpath = '../images';
        let funflug="l";
        if (this.enlive > 0) {
            if (this.fun == "l") {
                if (this.en_x > 0)
                    this.en_x = this.en_x - this.speed;
                else {
                    this.en_x = 0;
                    this.fun = "r";
                }
                funflug="l";
                //enpath = "../images/l";
            } else {
                if (this.en_x < max_width - 50) {
                    this.en_x = this.en_x + this.speed;
                } else {
                    this.en_x = max_width - 50;
                    this.fun = "l";
                }
                funflug="r";
                //enpath = "../images/r";
            }

            // if (this.enactionindex < this.enactioncount) {
            //     eImg.src =require(enpath + "/" + this.enactionindex.toString() + ".png");
            //     this.enactionindex = this.enactionindex + 1;
            // } else {
            //     eImg.src = require(enpath + "/1.png");
            //     this.enactionindex = 1;
            // }
            if (this.enactionindex < this.enactioncount) {
                eImg.src =require('../images/'+funflug + "/" + this.enactionindex.toString() + ".png");
                this.enactionindex = this.enactionindex + 1;
            } else {
                eImg.src =require('../images/'+funflug + "/1.png");
                this.enactionindex = 1;
            }
            ptctx?.drawImage(eImg, 0, 0, eImg.width, eImg.height, this.en_x, this.en_y, this.enwidth, this.enheight
            );
        }
    }

    enemydeaddraw=(ptctx:any)=>{
        let eImg = new Image();

        if (this.enlive <= 0) {
            this.enwidth = 40;
            this.enheight = 30;
            //死亡
            if (this.fun == "l") {

                if (this.currentdeadstr == "../images/l/diedl_0.png") {
                    eImg.src = require("../images/l/diedl_1.png");
                    this.currentdeadstr="../images/l/diedl_1.png";
                }
                else {
                    eImg.src = require("../images/l/diedl_0.png");
                    this.currentdeadstr="../images/l/diedl_0.png";
                }
            } else {

                if (this.currentdeadstr == "../images/r/diedr_0.png") {
                    eImg.src = require("../images/r/diedr_1.png");
                    this.currentdeadstr="../images/r/diedr_1.png";
                }
                else {
                    eImg.src = require("../images/r/diedr_0.png");
                    this.currentdeadstr="../images/r/diedr_0.png";
                }
            }
            ptctx?.drawImage(eImg, 0, 0, eImg.width, eImg.height, this.en_x, this.en_y+this.enheight/2, this.enwidth, this.enheight);
        }
    }

}

